#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "uthash.h"

#include <iso646.h>

/**
 * Return an array of arrays of size *returnSize.
 * The sizes of the arrays are returned as *returnColumnSizes array.
 * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
 */
int** construct2DArray(int* original, int originalSize, int m, int n, int* returnSize, int** returnColumnSizes);

int main()
{
	return 0;
}

int** construct2DArray(int* original, int originalSize, int m, int n, int* returnSize, int** returnColumnSizes)
{
	int i = 0;
	int** result = NULL;

	if (m * n != originalSize) {
		*returnSize = 0;
		*returnColumnSizes = NULL;
		return result;
	}

	result = (int**)malloc(sizeof(int*) * m);
	*returnSize = m;
	*returnColumnSizes = (int*)malloc(sizeof(int) * m);

	for (i = 0; m > i; i++) {
		/* 在此处直接切割原数组。 */
		result[i] = original + i * n;
		(*returnColumnSizes)[i] = n;
	}

	return result;
}
